import request from '@/axios';
import website from '@/config/website';

export const loginByUsername = (account, password, type, key, code) => request({
  url: '/api/civil-auth/token',
  method: 'post',
  headers: {
    'Captcha-Key': key,
    'Captcha-Code': code
  },
  params: {
    grantType: (website.captchaMode ? 'captcha' : 'password'),
    account,
    password,
    type
  }
});

export const loginBySocial = (source, code, state) => request({
  url: '/api/civil-auth/token',
  method: 'post',
  params: {
    source,
    code,
    state,
    grantType: 'social',
    scope: 'all'
  }
});

export const getButtons = () => request({
  url: '/api/civil-system/menu/buttons',
  method: 'get'
});

export const getUserInfo = () => request({
  url: '/api/user/getUserInfo',
  method: 'get'
});

export const refreshToken = (refreshToken) => request({
  url: '/api/civil-auth/token',
  method: 'post',
  params: {
    refreshToken,
    grantType: 'refresh_token',
    scope: 'all'
  }
});

export const registerGuest = (form, oauthId) => request({
  url: '/api/civil-user/register-guest',
  method: 'post',
  params: {
    name: form.name,
    account: form.account,
    password: form.password,
    oauthId
  }
});

export const getMenu = () => request({
  url: '/api/civil-system/menu/routes',
  method: 'get'
});

export const getCaptcha = () => request({
  url: '/api/civil-auth/captcha',
  method: 'get'
});

export const getTopMenu = () => request({
  url: '/api/user/getTopMenu',
  method: 'get'
});

export const sendLogs = (list) => request({
  url: '/api/user/send-logs',
  method: 'post',
  data: list
});

export const logout = () => request({
  url: '/api/civil-auth/logout',
  method: 'post'
});
